define([
	"angular",
	"framework/time/TimeModule",
	"framework/tabindex/TabindexModule",
	"framework/msg/GillionMsgModule",
	"framework/datasource/DataSourceModule",
	"framework/dataGrid/DataGridModule",
	"framework/pagination/GillionPaginationModule"
	],function(angular){
	/**
	 * [TestModule description]
	 * @type {[type]}
	 */
	var TestModule=angular.module('TestModule',['TimeModule','TabindexModule','GillionMsgModule','DataSourceModule','DataGridModule','GillionPaginationModule']);

	TestModule.controller('Controller1',function ($scope,Resource,GillionMsg,$dataSourceManager,$dataSource) {
		/*var http=Resource("/test/student/query/:path",null);
*/
		

		var students=Resource("/business/students/:path",null);

		$scope.findStudent=function(){
			http.get({"path":1},function(result){
				if (result.success) {
					GillionMsg.alert("查询成功");
				}
			});
		}

		$scope.searchParams={
			studentName:"1"
		}

		$dataSourceManager.getDataSource("student").then(function(dataSource){
			console.info(dataSource);
		})

		$scope.updateStudent=function(){
			students.update($scope.student,function(student){
				GillionMsg.alert("更新成功");
				$scope.searchStudent();
			});
			
		};
		$scope.deleteStudent=function(){
			students.delete({path:$scope.student.studentId},function(result){
				
				GillionMsg.alert("删除成功");
				
			});
			
		};
		$scope.createStudent=function(){
			$scope.StudentForm.verify();
			if($scope.StudentForm.$valid){
			students.create($scope.student,function(student){
					$scope.student=student;
					GillionMsg.alert("保存成功");
					$scope.searchStudent();
									
			});
			}
		};
		$scope.searchStudent=function(){
			students.query($scope.search,function(students){
			$scope.students=students;
			});
		}
		$scope.studentLoadSuccess= function(grid,source){
			$scope.lookDtail=function(){
				selectedSource=[];
				for (var i = 0; i < grid.rowStates.length; i++) {
					if(grid.rowStates[i].checked){
						selectedSource.push(source[i])
					}
				}
			alert("当前选中"+selectedSource);
			}
			grid.actions.removeStudent=function(row){
				students.delete({path:row.studentId},function(result){
				
				GillionMsg.alert("删除成功");
				$scope.searchStudent();
			
			});
				/*for (var i = 0; i < source.length; i++) {
					if(source[i]==row){
						source.shift(i,1);
					}
				}*/
				/*alert(row.studentId);*/
			}
		}
		$scope.search={};
		$scope.searchStudent = function(){
			$dataSourceManager.dataSources['student'].doRequestData(null,$scope.search,function(dataSource){
			   $scope.student=dataSource;
			});
		};
		$scope.addClass=function(){
			var addClass=Resource("/business/addClass/:path",null);
			addClass.create($scope.testclass,function(testclass){
				$scope.testclass=testclass;
				GillionMsg.alert("添加成功");
			});
		};
		$scope.updateClass=function(){
			var updClass=Resource("/business/updClass/:path",null);
			updClass.update($scope.testclass,function(student){
				GillionMsg.alert("修改成功");
			});
		};
		$scope.rootExcel=function(){
			var rootExcel=Resource("/business/queryList/:path",null);
			rootExcel.get(null,function(){
				GillionMsg.alert("导出成功");
			});
		};
	});
});